<template>
	<view class="wrap">
		<view class="section_4 flex-row" @click="loginOut()">
		  <text class="text_12">退出登陆</text>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				
			}
		},
		methods:{
			async loginOut(){
				await this.$u.post('/api/auth/logout').then(res=>{
					console.log(res)
					// 状态码为204,即代表退出登录成功
					if(res.statusCode===204){
						// 清除用户信息
						this.$u.vuex('vuex_token',null);
						this.$u.vuex('vuex_user',{});
						uni.showModal({
							title:'确定要退出登陆？',
							success: function(res) {
								if (res.confirm) {
									// 点击确认跳转到登陆界面
									setTimeout(res=>{
										uni.$u.route({
											type:'reLaunch',
											url: 'pages/index/index'
										})
									},1000)
									uni.showToast({
										title:'退出登陆成功',
										icon:'success'
									})
								} else if(res.cancel){
								}
							}
						})
						
					}else{
						uni.showToast({
							title:'网络异常',
							icon:'error'
						})
					}
				}).catch(err=>{
					console.log(err)
				})
			}
			
		}
	}
</script>

<style lang="scss" scoped>
	.wrap{
		padding-bottom: 100px;
	}
	.section_4 {
	  margin-top: 32rpx;
	  color: rgb(0, 0, 0);
	  font-size: 34rpx;
	  line-height: 48rpx;
	  white-space: nowrap;
	  padding: 26rpx 42rpx;
	  text-align: center;
	  background-color: rgb(255, 255, 255);
	}
	.image_13 {
	  width: 44rpx;
	  height: 44rpx;
	}
	.text_12 {
	  margin-left: 34rpx;
	}
</style>
